package com.xuxu.blog.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xuxu.blog.entity.PointEntity;
import com.xuxu.blog.service.PointService;
import com.xuxu.common.utils.PageUtils;
import com.xuxu.common.utils.R;


/**
 * @author maxuxu
 * @email maxuxu019@gmail.com
 * @date 2022-08-21 22:22:31
 */
@RestController
@RequestMapping("blog/point")
@Api(value = "PointController", tags = "充值积分")
@Slf4j
public class PointController {
    @Autowired
    private PointService pointService;

    /**
     * 查找所有的积分情况
     */
    @RequestMapping("/findAll")
    public R findAll() {
        List<PointEntity> list = pointService.list();
        return R.ok().put("data", list);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = pointService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        PointEntity point = pointService.getById(id);

        return R.ok().put("point", point);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PointEntity point) {
        pointService.save(point);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PointEntity point) {
        pointService.updateById(point);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        pointService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
